﻿namespace net.zxteam.ZXLexer.Rules.Internal
{
	using net.zxteam.ZXLexer.Tokens;
	using System.Collections.Generic;

	internal abstract class CollectionRuleBase : InnerRule, ICollection<IInnerRule>, IInnerRule
	{
		private readonly List<IInnerRule> _children = new List<IInnerRule>();

		public IList<IInnerRule> Children { get { return _children; } }

		public CollectionRuleBase(IRule parentRule) : base(parentRule) { }

		public void Add(IInnerRule item) { _children.Add(item); }

		public void Clear() { _children.Clear(); }

		public bool Contains(IInnerRule item) { return _children.Contains(item); }

		public void CopyTo(IInnerRule[] array, int arrayIndex) { _children.CopyTo(array, arrayIndex); }

		public int Count { get { return _children.Count; } }

		public bool IsReadOnly { get { return false; } }

		public bool Remove(IInnerRule item) { return _children.Remove(item); }

		public IEnumerator<IInnerRule> GetEnumerator() { return _children.GetEnumerator(); }

		System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return this.GetEnumerator(); }
	}
}
